import { history } from 'umi';
import { isIframe } from './utils/iframe';

/**
 * @see https://umijs.org/zh-CN/plugins/plugin-access
 * */
export default function access(
  initialState: { currentUser?: AccountData.CurrentAccountVo } | undefined,
) {
  const { currentUser } = initialState ?? {};
  const permissionsArray = currentUser?.permissions || [];
  const permissionsStr = permissionsArray.toString() || '';

  //嵌套模式，isIframe
  //在嵌套
  const inIframe = isIframe();
  // const inIframe = true;

  //不在嵌套中
  const unIfram = !inIframe;

  // 如果不是登录页面，执行
  const { location } = history;

  return {
    /**
     * ======================================================================================
     * 选题管理
     * ======================================================================================
     */
    inIframeShowCues: inIframe && permissionsStr.indexOf('cues') > -1,
    unIframShowCues: unIfram && permissionsStr.indexOf('cues') > -1,

    /**
     * 线索征集
     */
    inIframeShowCuesTopic: inIframe && permissionsStr.indexOf('cues:topic') > -1,
    unIframShowCuesTopic: unIfram && permissionsStr.indexOf('cues:topic') > -1,


    选题计划x收录: permissionsArray.includes('cues:topic:page'),

    线索征集x页面: permissionsArray.includes('cues:topic:adopt'),

    线索征集x配置x管理员: permissionsArray.includes('cues:topic:config:manage'),
    线索征集x配置x部门需求者: permissionsArray.includes('cues:topic:config:need:department'),
    线索征集x配置x媒体需求者: permissionsArray.includes('cues:topic:config:need:media'),
    线索征集x配置x提供者: permissionsArray.includes('cues:topic:config:render'),

    线索征集x创建选题计划: permissionsArray.includes('cues:topic:add'),

    线索征集x报送线索x页面: permissionsArray.includes('cues:topic:submit:page'),
    线索征集x报送线索x附件: permissionsArray.indexOf('cues:topic:submit:attachment') > -1,
    线索征集x报送线索x附件x图片: permissionsArray.includes('cues:topic:submit:attachment:picture'),
    线索征集x报送线索x附件x视频: permissionsArray.includes('cues:topic:submit:attachment:video'),
    线索征集x报送线索x附件x办公: permissionsArray.includes('cues:topic:submit:attachment:office'),
    线索征集x报送线索x附件x其他: permissionsArray.includes('cues:topic:submit:attachment:other'),

    /**
     * 主动报送 （线索汇聚）
     */
    inIframeShowCuesActive: inIframe && permissionsStr.indexOf('cues:active') > -1,
    unIframShowCuesActive: unIfram && permissionsStr.indexOf('cues:active') > -1,

    主动报送x页面: permissionsArray.includes('cues:active:page'),
    主动报送x配置x管理员: permissionsArray.includes('cues:active:config:manage'),
    主动报送x配置x接收者: permissionsArray.includes('cues:active:config:need'),
    主动报送x配置x提供者: permissionsArray.includes('cues:active:config:render'),

    主动报送x报送线索x页面: permissionsArray.includes('cues:active:submit:page'),
    主动报送x报送线索x附件: permissionsArray.indexOf('cues:active:submit:attachment') > -1,
    主动报送x报送线索x附件x图片: permissionsArray.includes('cues:active:submit:attachment:picture'),
    主动报送x报送线索x附件x视频: permissionsArray.includes('cues:active:submit:attachment:video'),
    主动报送x报送线索x附件x办公: permissionsArray.includes('cues:active:submit:attachment:office'),
    主动报送x报送线索x附件x其他: permissionsArray.includes('cues:active:submit:attachment:other'),

    /**
     *  数据分析
     */
    inIframeShowCuesAnalysis: inIframe && permissionsStr.indexOf('cues:analysis') > -1,
    unIframShowCuesAnalysis: unIfram && permissionsStr.indexOf('cues:analysis') > -1,

    数据分析x页面: permissionsArray.includes('cues:analysis:page'),

    /**
     * ======================================================================================
     * 宣传指令
     * ======================================================================================
     */
    inIframeShowInstruct: inIframe && permissionsStr.indexOf('instruct') > -1,
    unIframShowInstruct: unIfram && permissionsStr.indexOf('instruct') > -1,

    宣传指令x页面: permissionsArray.includes('instruct:page'),
    宣传指令x配置x通讯录修改专员: permissionsArray.includes('instruct:config:commissioner'),
    宣传指令x配置x管理员: permissionsArray.includes('instruct:config:manage'),
    宣传指令x配置x接收者: permissionsArray.includes('instruct:config:recipient'),
    宣传指令x配置x指令审批: permissionsArray.includes('instruct:config:examine'),
    宣传指令x联络人: permissionsArray.includes('instruct:address'),
    宣传指令x发布指令x页面: permissionsArray.includes('instruct:submit:page'),
    宣传指令x发布指令x附件: permissionsArray.indexOf('instruct:submit:attachment') > -1,
    宣传指令x发布指令x附件x图片: permissionsArray.includes('instruct:submit:attachment:picture'),
    宣传指令x发布指令x附件x视频: permissionsArray.includes('instruct:submit:attachment:video'),
    宣传指令x发布指令x附件x办公: permissionsArray.includes('instruct:submit:attachment:office'),
    宣传指令x发布指令x附件x其他: permissionsArray.includes('instruct:submit:attachment:other'),

    /**
     * ======================================================================================
     * 文化报表（质效评估）
     * ======================================================================================
     */
    inIframeShowAssess: inIframe && permissionsStr.indexOf('assess') > -1,
    unIframShowAssess: unIfram && permissionsStr.indexOf('assess') > -1,

    质效考核x页面: permissionsArray.includes('assess:page'),

    质效评估x配置x管理员: permissionsArray.includes('assess:config:manage'),
    质效评估x配置x运营员: permissionsArray.includes('assess:config:operate'),
    质效评估x配置x提供者: permissionsArray.includes('assess:config:render'),
    质效评估x来源: permissionsArray.includes('assess:source'),

    质效评估x创建x页面: permissionsArray.includes('assess:create:page'),
    质效评估x创建x附件: permissionsArray.indexOf('assess:create:attachment') > -1,
    质效评估x创建x附件x图片: permissionsArray.includes('assess:create:attachment:picture'),
    质效评估x创建x附件x视频: permissionsArray.includes('assess:create:attachment:video'),
    质效评估x创建x附件x办公: permissionsArray.includes('assess:create:attachment:office'),
    质效评估x创建x附件x其他: permissionsArray.includes('assess:create:attachment:other'),

    质效评估x更新: permissionsArray.includes('assess:update'),
    质效评估x考核: permissionsArray.includes('assess:examine'),

    /**
     * ======================================================================================
     * 数据仓
     * ======================================================================================
     */
    inIframeShowDatahub: inIframe && permissionsStr.indexOf('datahub') > -1,
    unIframShowDatahub: unIfram && permissionsStr.indexOf('datahub') > -1,

    数据仓x配置x管理员: permissionsArray.includes('datahub:config:manage'),
    数据仓x配置x运营员: permissionsArray.includes('assess:config:operate'),
    数据仓x配置x订阅人: permissionsArray.includes('datahub:config:subscriber'),

    数据仓x记录: permissionsArray.includes('datahub:record'),
    数据仓x来源配置: permissionsArray.includes('datahub:source'),
    数据仓x同步配置: permissionsArray.includes('datahub:synchrony'),
    数据仓x标注: permissionsArray.includes('datahub:mark'),
    数据仓x标签: permissionsArray.includes('datahub:label'),
    数据仓x关键字: permissionsArray.includes('datahub:keyword'),
    数据仓x地域管理: permissionsArray.includes('datahub:area'),

    /**
     * ======================================================================================
     * 热搜热榜
     * ======================================================================================
     */
    inIframeShowTophub: inIframe && permissionsStr.indexOf('tophub') > -1,
    unIframShowTophub: unIfram && permissionsStr.indexOf('tophub') > -1,

    热搜热榜x配置x管理员: permissionsArray.includes('tophub:config:manage'),
    热搜热榜x配置x运营员: permissionsArray.includes('tophub:config:operate'),

    热搜热榜x上榜记录: permissionsArray.includes('tophub:record'),
    热搜热榜x实时热搜: permissionsArray.includes('tophub:hot'),
    热搜热榜x运营页面: permissionsArray.includes('tophub:operate'),
    热搜热榜x来源配置: permissionsArray.includes('tophub:source'),
    热搜热榜x同步配置: permissionsArray.includes('tophub:synchrony'),

    /**
     * ======================================================================================
     * 监看监听
     * ======================================================================================
     */
    inIframeShowMonitor: inIframe && permissionsStr.indexOf('monitor') > -1,
    unIframShowMonitor: unIfram && permissionsStr.indexOf('monitor') > -1,

    inIframe监听监看x图文审读: inIframe && permissionsArray.includes('monitor:article'),
    unIfram监听监看x图文审读: unIfram && permissionsArray.includes('monitor:article'),

    inIframe监听监看x视听监测: inIframe && permissionsArray.includes('monitor:video'),
    unIfram监听监看x视听监测: unIfram && permissionsArray.includes('monitor:video'),

    inIframe监听监看x直播管理: inIframe && permissionsArray.includes('monitor:live'),
    unIfram监听监看x直播管理: unIfram && permissionsArray.includes('monitor:live'),

    inIframe监听监看x联动处置: inIframe && permissionsArray.includes('monitor:linkage'),
    unIfram监听监看x联动处置: unIfram && permissionsArray.includes('monitor:linkage'),

    /**
     * ======================================================================================
     * 每日要情
     * ======================================================================================
     */
    inIframeShowNews: inIframe && permissionsStr.indexOf('news') > -1,
    unIframShowNews: unIfram && permissionsStr.indexOf('news') > -1,

    每日要情x要情记录: permissionsArray.includes('news:record'),
    每日要情x要情管理: permissionsArray.includes('news:manage'),

    /**
     * ======================================================================================
     * 数据分析
     * ======================================================================================
     */

    inIframeShow数据分析x用户分析: permissionsArray.includes('analysis:user'),
    unIframShow数据分析x用户分析: permissionsArray.includes('analysis:user'),

    /**
     * ======================================================================================
     * 采访要素匹配
     * ======================================================================================
     */

    采访要素匹配x管理员: permissionsArray.includes('interview:config:manage'),
    采访要素匹配x采访媒体: permissionsArray.includes('interview:config:interviewer'),
    采访要素匹配x采访对象: permissionsArray.includes('interview:config:interviewee'),
    /**
     * ======================================================================================
     * 系统管理
     * ======================================================================================
     */
    inIframeShowAdmin: inIframe && permissionsStr.indexOf('admin') > -1,
    unIframShowAdmin: unIfram && permissionsStr.indexOf('admin') > -1,
    系统管理x组织管理: permissionsArray.includes('admin:organization'),
    系统管理x角色管理: permissionsArray.includes('admin:role'),
    系统管理x权限管理: permissionsArray.includes('admin:permission'),

    /**
     * ======================================================================================
     * 个人中心
     * ======================================================================================
     */
    inIframeShowPersonal: inIframe && permissionsStr.indexOf('personal') > -1,
    unIframShowPersonal: unIfram && permissionsStr.indexOf('personal') > -1,
    个人中心x页面: permissionsArray.includes('personal:page'),
    /**
     * ======================================================================================
     * 设置
     * ======================================================================================
     */
    inIframeShowSetting: inIframe && permissionsStr.indexOf('setting') > -1,
    unIframShowSetting: unIfram && permissionsStr.indexOf('setting') > -1,
    设置x页面: permissionsArray.includes('setting:page'),

    /**
     * ======================================================================================
     * 工具集
     * ======================================================================================
     */
    inIframeShowTool: inIframe && permissionsStr.indexOf('tool') > -1,
    unIframShowTool: unIfram && permissionsStr.indexOf('tool') > -1,
    工具集x页面: permissionsArray.includes('tool:page'),

    /**
     * ======================================================================================
     * 技术支持
     * ======================================================================================
     */
    inIframeShowFeedback: inIframe && permissionsStr.indexOf('feedback') > -1,
    unIframShowFeedback: unIfram && permissionsStr.indexOf('feedback') > -1,

    技术支持x页面: permissionsArray.includes('feedback:page'),
  };
}
